home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-19 | 7.8 KB | 323 lines | [TEXT/MPS ] |
- #include <UMacApp.h>
- #include <UPrinting.h>
- #include <UTEView.h>
- #include <Fonts.h>
- #include <ToolUtils.h>
-
- #include "editor.h"
-
- // ***** Global constants
-
- const OSType kSignature = 'JLMT';
- const OSType kFileType = 'JL01';
- const int kWindowID = 1002;
-
- // ***** Class TEditor
-
- pascal TEditor::TEditor(OSType itsMainFileType)
- {
- TEditView *aEditView;
- TBoxView *aBoxView;
-
- IApplication(itsMainFileType);
-
- if (gDeadStripSuppression)
- {
- aEditView = new TEditView;
- aBoxView = new TBoxView;
- }
- }
-
- pascal struct TDocument *TEditor::DoMakeDocument(CmdNumber itsCmdNumber)
- {
- TEditDocument* aEditDocument;
- aEditDocument = new TEditDocument;
- FailNIL(aEditDocument);
- return aEditDocument;
- }
-
- pascal void TEditor::HandleFinderRequest() {};
-
- #ifdef qDebug
- pascal void TEditor::IdentifySoftware()
- {
- ProgramReport("\pEditor ©J.Langowski/MacTutor May 1991",false);
- inherited::IdentifySoftware();
- }
- #endif
-
-
- // ***** Class TEditDocument
-
- pascal TEditDocument::TEditDocument()
- {
- IDocument(kFileType, kSignature, kUsesDataFork,
- !kUsesRsrcFork, !kDataOpen, !kRsrcOpen);
- fSavePrintInfo = true; // save print info in data fork
- }
-
- pascal void TEditDocument::DoMakeViews(Boolean forPrinting)
- {
- VRect itsExtent;
- Rect itsQDExtent;
-
- TBoxView *aBoxView;
- TEditBox *aEditBox;
-
- TWindow *aWindow;
-
- aWindow = NewTemplateWindow(kWindowID,this);
- FailNIL(aWindow);
-
- aWindow->SimpleStagger(kStdStaggerAmount, kStdStaggerAmount, &gStdStaggerCount);
-
- fEditView = (TEditView*) aWindow->FindSubView('scrl');
- FailNIL(fEditView);
- fEditView->IEditView(this);
-
- aWindow->Show(true,false); // so view can be focused
-
- if (fEditView->Focus()) // must focus for ViewToQDRect
- {
- aBoxView = (TBoxView*) aWindow->FindSubView('tx01');
- FailNIL(aBoxView);
- aBoxView->GetFrame(&itsExtent);
- fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
- aEditBox = new TEditBox(&itsQDExtent,aBoxView,this);
- FailNIL(aEditBox);
- fEditView->AddShape(aEditBox);
-
- aBoxView = (TBoxView*) aWindow->FindSubView('tx02');
- FailNIL(aBoxView);
- aBoxView->GetFrame(&itsExtent);
- fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
- aEditBox = new TEditBox(&itsQDExtent,aBoxView,this);
- FailNIL(aEditBox);
- fEditView->AddShape(aEditBox);
-
- aWindow->SetTarget(aBoxView); // just for testing, set to view no. 2
-
- aBoxView = (TBoxView*) aWindow->FindSubView('tx03');
- FailNIL(aBoxView);
- aBoxView->GetFrame(&itsExtent);
- fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
- aEditBox = new TEditBox(&itsQDExtent,aBoxView,this);
- FailNIL(aEditBox);
- fEditView->AddShape(aEditBox);
-
- aBoxView = (TBoxView*) aWindow->FindSubView('tx04');
- FailNIL(aBoxView);
- aBoxView->GetFrame(&itsExtent);
- fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
- aEditBox = new TEditBox(&itsQDExtent,aBoxView,this);
- FailNIL(aEditBox);
- fEditView->AddShape(aEditBox);
- }
-
- }
-
- pascal void TEditDocument::DoNeedDiskSpace(long *dataForkBytes, long *rsrcForkBytes)
- {
- }
-
- pascal void TEditDocument::DoRead(short aRefNum, Boolean rsrcExists, Boolean forPrinting)
- {
- }
-
- pascal void TEditDocument::DoWrite(short aRefNum, Boolean makingCopy)
- {
- }
-
- pascal void TEditDocument::Free()
- {
- }
-
- #ifdef qDebug
- pascal void TEditDocument::Fields(pascal void (*DoToField) (StringPtr fieldName,
- Ptr fieldAddr, short fieldType, void *link), void *link)
- {
- DoToField("\pTEditDocument", nil, bClass, link);
- DoToField("\pfEditView", (Ptr) &fEditView, bObject, link);
- inherited::Fields(DoToField, link);
- }
- #endif
-
- // ***** Shape class methods
-
- pascal TBox::TBox(Rect *itsLocation)
- { fLocation = *itsLocation;
- fSelected = false; }
-
- pascal void TBox::DrawShape()
- {
- // add code later for shape selections
- }
-
- #ifdef qDebug
- pascal void TBox::Fields(pascal void (*DoToField) (StringPtr fieldName,
- Ptr fieldAddr, short fieldType, void *link), void *link)
- {
- DoToField("\pTBox", nil, bClass, link);
- DoToField("\pfLocation", (Ptr) &fLocation, bRect, link);
- DoToField("\pfSelected", (Ptr) &fSelected, bBoolean, link);
- DoToField("\pfTagRgn", (Ptr) &fTagRgn, bRgnHandle, link);
- DoToField("\pfTL", (Ptr) &fTL, bRect, link);
- DoToField("\pfTR", (Ptr) &fTR, bRect, link);
- DoToField("\pfBL", (Ptr) &fBL, bRect, link);
- DoToField("\pfBR", (Ptr) &fBR, bRect, link);
- DoToField("\pfT", (Ptr) &fT, bRect, link);
- DoToField("\pfB", (Ptr) &fB, bRect, link);
- DoToField("\pfL", (Ptr) &fL, bRect, link);
- DoToField("\pfR", (Ptr) &fR, bRect, link);
- inherited::Fields(DoToField, link);
- }
- #endif
-
-
- pascal TShape::TShape(Rect *itsLocation) : (itsLocation)
- {
- fPenSize = 1;
-
- for (int i = 0; i<8 ; i++)
- { fPenPat[i] = qd.black[i];
- fFillPat[i] = qd.gray[i];
- }
- }
-
- #ifdef qDebug
- pascal void TShape::Fields(pascal void (*DoToField) (StringPtr fieldName,
- Ptr fieldAddr, short fieldType, void *link), void *link)
- {
- DoToField("\pTShape", nil, bClass, link);
- DoToField("\pfPenSize", (Ptr) &fPenSize, bInteger, link);
- DoToField("\pfPenPat", (Ptr) &fPenPat, bPattern, link);
- DoToField("\pfFillPat", (Ptr) &fFillPat, bPattern, link);
- inherited::Fields(DoToField, link);
- }
- #endif
-
-
- pascal TEditBox::TEditBox(Rect *itsLocation,
- TBoxView *itsView, TEditDocument *itsDocument) : (itsLocation)
- { fBoxView = itsView;
- fEditDocument = itsDocument;
- }
-
- pascal void TEditBox::DrawShape()
- {
- VRect itsExtent;
- Rect itsQDExtent;
-
- PenNormal();
- fBoxView->GetFrame(&itsExtent);
- fEditDocument->fEditView->ViewToQDRect(&itsExtent,&itsQDExtent);
- FrameRect(&itsQDExtent);
-
- inherited::DrawShape();
- }
-
- #ifdef qDebug
- pascal void TEditBox::Fields(pascal void (*DoToField) (StringPtr fieldName,
- Ptr fieldAddr, short fieldType, void *link), void *link)
- {
- DoToField("\pTEditBox", nil, bClass, link);
- DoToField("\pfBoxView", (Ptr) &fBoxView, bObject, link);
- DoToField("\pfEditDocument", (Ptr) &fEditDocument, bObject, link);
- inherited::Fields(DoToField, link);
- }
- #endif
-
- // ***** TBoxView methods
-
- pascal struct TCommand *TBoxView::DoMouseCommand(Point *theMouse,
- EventInfo *info, Point *hysteresis)
- {
- this->GetWindow()->SetTarget(this);
- inherited::DoMouseCommand(theMouse, info, hysteresis);
- return gNoChanges;
- }
-
- #ifdef qDebug
- pascal void TBoxView::Fields(pascal void (*DoToField) (StringPtr fieldName,
- Ptr fieldAddr, short fieldType, void *link), void *link)
- {
- DoToField("\pTBoxView", nil, bClass, link);
- inherited::Fields(DoToField, link);
- }
- #endif
-
-
- // ***** TEditView methods
-
- pascal void TEditView::IEditView(TEditDocument *itsDocument)
- {
- TStdPrintHandler *aStdPrintHandler;
- TList *aList;
-
- aStdPrintHandler = new TStdPrintHandler;
- FailNIL(aStdPrintHandler);
- aStdPrintHandler->IStdPrintHandler
- (nil,this,kSquareDots,kFixedSize,!kFixedSize);
- fPrintHandler = aStdPrintHandler;
-
- fDocument = itsDocument;
-
- aList = NewList();
- fShapeList = aList;
- }
-
- pascal void TEditView::AddShape(TBox *aBox)
- { fShapeList->InsertFirst(aBox); }
-
- pascal void TEditView::DeleteShape()
- { fShapeList->Delete(fShapeList->First()); }
-
- pascal void TEditView::ForEachShapeDo(pascal void (*DoToItem)
- (TObject *item, void *DoToItem_Staticlink),void *DoToItem_Staticlink)
- { fShapeList->Each(DoToItem,DoToItem_Staticlink); }
-
-
- pascal void DrawYourself(TBox *aBox, void *link)
- { aBox->DrawShape(); }
-
- pascal void TEditView::Draw(Rect *area)
- {
- void *link;
- ForEachShapeDo((DoToObject)DrawYourself,link);
- }
-
-
- pascal void TEditView::Free()
- {
- }
-
- #ifdef qDebug
- pascal void TEditView::Fields(pascal void (*DoToField) (StringPtr fieldName,
- Ptr fieldAddr, short fieldType, void *link), void *link)
- {
- DoToField("\pTEditView", nil, bClass, link);
- DoToField("\pfDocument", (Ptr) &fDocument, bObject, link);
- DoToField("\pfShapeList", (Ptr) &fShapeList, bObject, link);
- inherited::Fields(DoToField, link);
- }
- #endif
-
-
- TEditor *gEditor;
-
- int main()
- {
- InitToolBox();
- if (ValidateConfiguration(&gConfiguration))
- {
- InitUMacApp(8);
- InitUPrinting();
- InitUTEView();
- gEditor = new TEditor(kFileType);
- FailNIL(gEditor);
- gEditor->Run();
- }
- else StdAlert(phUnsupportedConfiguration);
- return 0;
- }
-